package name.fowler.refactoring.simplestore.service;

import name.fowler.refactoring.simplestore.Customer;
import name.fowler.refactoring.simplestore.Movie;
import name.fowler.refactoring.simplestore.PriceCode;
import name.fowler.refactoring.simplestore.Rental;

public class AmountService {

    public static double getAmount(Customer customer) {
        double result = 0;
        for (Rental rental : customer.getRentals()) {
            result += getAmount(rental);
        }
        return result;
    }

    public static double getAmount(Rental rental) {
        double result = 0;
        
        result += getAmount((rental.getMovie()), rental.getDaysRented());
       
        return result;
    }

    public static double getAmount(Movie movie, int daysRented) {
        PriceCode priceCode = movie.getPriceCode();
        double result = priceCode.getBaseCost();
        if (daysRented > priceCode.getIncludedDays()) {
            result += (daysRented - priceCode.getIncludedDays()) * priceCode.getCostPerDay();
        }
        return result;
    }
} 